#include "StringEditEntry.h"
#include <QPointer>
#include "EntryLineEdit.h"

struct StringEditEntry::StringEditEntryPrivate {
    QPointer<EntryLineEdit> edit;
};

StringEditEntry::~StringEditEntry() { }

StringEditEntry::StringEditEntry(QWidget *parent) : EditEntry{parent} {
    p.reset(new StringEditEntryPrivate);
    p->edit = new EntryLineEdit;
    addEditControll(p->edit);

    connect(p->edit, &QLineEdit::editingFinished, this, &StringEditEntry::onEditingFinished);
}

void StringEditEntry::setValue(const QString &text) {
    if(!p->edit->hasFocus()) {
        p->edit->setText(text);
    }
}

QString StringEditEntry::value() const {
    return p->edit->text();
}

void StringEditEntry::onEditingFinished() {
    emit valueChanged(p->edit->text());
}

